home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / morrison / dir.cb < prev    next >
Text File  |  1989-11-02  |  22KB  |  957 lines

  1. /* --------------------------------------------------------------------------- */
  2. /*                                                                                                  */
  3. /*                                     DIR Macro                                                 */
  4. /*                                                                                                  */
  5. /* --------------------------------------------------------------------------- */
  6. /*                                                                                                  */
  7. /*         This macro is designed to operate simular to the menus seen in      */
  8. /*         the popular NORTON COMMANDER program.    You can go UP or DOWN the     */
  9. /*         tree structure on the disk by moving the cursor over the proper     */
  10. /*         <DIR> entry in the directory and hitting the <Enter> key.             */
  11. /*                                                                                                  */
  12. /*         If the <Enter> key is hit and a file (instead of a directory         */
  13. /*         <DIR> entry) is highlighted then this file will be loaded into      */
  14. /*         BRIEF and be ready for editing.                                                 */
  15. /*                                                                                                  */
  16. /*         The <Ins> or <Space> key will TOGGLE the file marker for the         */
  17. /*         file that is currently highlighted.  <DIR> files MAY NOT BE          */
  18. /*         marked as they can not be edited.  After having marked one or         */
  19. /*         more (as many as you like) you can then have ALL of the MARKED      */
  20. /*         files loaded into BRIEF by hitting the <Alt-L> key.                     */
  21. /*                                                                                                  */
  22. /*         If you do NOT wish to edit any files, simply hit the <Esc> key      */
  23. /*         and you will be back editing the file that you started with.         */
  24. /*                                                                                                  */
  25. /*         The <Home>, <End>, <Up>, <Down>, <PgUp>, and <PgDn> keys are         */
  26. /*         used to move you around within the directory.                             */
  27. /*                                                                                                  */
  28. /*         Written BY:  Robert H. Morrison, 1 July 1988                              */
  29. /*                      Karlsruhe, West Germany                                             */
  30. /*                                                                                                  */
  31. /*         Last Update: 6 July 1988                                                         */
  32. /*                                                                                                  */
  33. /*                                                                                                  */
  34.  
  35. #define LINE      3
  36. #define SYSTEM       1
  37.  
  38. #define UP_DIR       ".."
  39. #define DOWN_DIR      ".\\"
  40.  
  41. #define SELECT       1
  42. #define UNSELECT 2
  43.  
  44. #define ALT_KEY      8
  45.  
  46. #include "dialog.h"
  47.  
  48. _init (...)
  49. {
  50.     int    mark_typ,
  51.             updir,
  52.             alt_done,
  53.             rows,
  54.             cols;
  55.  
  56.     string    new_file,
  57.                 bhelp,
  58.                 bdirfile,
  59.                 bdirpgm,
  60.                 bdiropt,
  61.                 bdirtxt,
  62.                 old_opt,
  63.                 select,
  64.                 unselect,
  65.                 alt_search,
  66.                 bdir;
  67.  
  68.     global    new_file,
  69.                 bhelp,
  70.                 bdirfile,
  71.                 bdirpgm,
  72.                 bdiropt,
  73.                 bdirtxt,
  74.                 old_opt,
  75.                 select,
  76.                 unselect,
  77.                 alt_search,
  78.                 alt_done,
  79.                 bdir,
  80.                 mark_typ,
  81.                 updir,
  82.                 rows,
  83.                 cols;
  84.  
  85.     alt_search = "\<■\|  ";
  86.     alt_done = FALSE;
  87.     bhelp = lower (inq_environment ("BHELP"));
  88.     if (bhelp != "")
  89.         bhelp += "\\";
  90.     bdiropt = "F";
  91.     bdirfile = bhelp + "temp.dir";
  92.     bdirpgm = bhelp + "bmakedir.exe";
  93.     bdirtxt = bhelp + "bmakedir.txt";
  94.     bdir = bdirpgm + ((" \-" + bdiropt) + (" \>&" + bdirfile));
  95.     inq_screen_size (rows, cols);
  96.     rows -= 10;
  97.     cols -= 42;
  98.     cols /= 2;
  99. }
  100.  
  101. dir (...)
  102. {
  103.     extern    to_bottom,
  104.                 display_file_name;
  105.  
  106.     int    dir_buffer,
  107.             old_buffer,
  108.             dir_window,
  109.             old_window,
  110.             end_line,
  111.             line;
  112.  
  113.     string    temp,
  114.                 this_line,
  115.                 current_dir,
  116.                 current_drive,
  117.                 answer;
  118.  
  119.     global    end_line,
  120.                 this_line,
  121.                 line,
  122.                 old_buffer,
  123.                 dir_buffer,
  124.                 current_dir,
  125.                 current_drive,
  126.                 answer;
  127.  
  128.     new_file = "";
  129.     message ("Reading disk directory...");
  130.     dos (bdir);
  131.     old_buffer = inq_buffer ();
  132.     dir_buffer = create_buffer ("DIR Ver 1.00", bdirtxt, SYSTEM);
  133.     create_window (cols, rows + 4, cols + 42, 3, "Ins - + Enter F1 F2 F4 F7 F8 F9 F10 Esc");
  134.     attach_buffer (dir_buffer);
  135.     set_buffer (dir_buffer);
  136.     getwd (NULL, current_dir);
  137.     current_dir = upper (current_dir);
  138.     current_drive = substr (current_dir, 1, 1);
  139.     top_of_buffer ();
  140.     read_file (bdirfile);
  141.     up ();
  142.     inq_position (end_line, NULL);
  143.     top_of_buffer ();
  144.  
  145.     keyboard_push ();
  146.     assign_to_key ("<Space>", "no_beep");
  147.     assign_to_key ("<Enter>", "select_dir");
  148.     assign_to_key ("<Home>", "top_of_dir");
  149.     assign_to_key ("<End>", "end_of_dir");
  150.     assign_to_key ("<Up>", "up_dir");
  151.     assign_to_key ("<Down>", "down_dir");
  152.     assign_to_key ("<PgUp>", "pgup_dir");
  153.     assign_to_key ("<PgDn>", "pgdown_dir");
  154.     assign_to_key ("<Ins>", "mark_dir");
  155.     assign_to_key ("<Ctrl-PgUp>", "up_1_dir");
  156.     assign_to_key ("<F1>", "help_dir");
  157.     assign_to_key ("<F2>", "change_drive");
  158.     assign_to_key ("<F4>", "load_marked");
  159.     assign_to_key ("<F7>", "make_dir");
  160.     assign_to_key ("<F8>", "delete_file");
  161.     assign_to_key ("<F9>", "set_mode");
  162.     assign_to_key ("<F10>", "_exit");
  163.     assign_to_key ("<Esc>", "_exit");
  164.     assign_to_key ("<Ctrl-\\>", "root_dir");
  165.     assign_to_key ("<\\>", "root_dir");
  166.     assign_to_key ("<Ctrl-R>", "read_dir");
  167.     assign_to_key ("<Keypad-minus>", "unselect_marks");
  168.     assign_to_key ("<Keypad-plus>", "select_marks");
  169.     assign_to_key ("<Alt-a>", "NC_alt_search a");
  170.     assign_to_key ("<Alt-b>", "NC_alt_search b");
  171.     assign_to_key ("<Alt-c>", "NC_alt_search c");
  172.     assign_to_key ("<Alt-d>", "NC_alt_search d");
  173.     assign_to_key ("<Alt-e>", "NC_alt_search e");
  174.     assign_to_key ("<Alt-f>", "NC_alt_search f");
  175.     assign_to_key ("<Alt-g>", "NC_alt_search g");
  176.     assign_to_key ("<Alt-h>", "NC_alt_search h");
  177.     assign_to_key ("<Alt-i>", "NC_alt_search i");
  178.     assign_to_key ("<Alt-j>", "NC_alt_search j");
  179.     assign_to_key ("<Alt-k>", "NC_alt_search k");
  180.     assign_to_key ("<Alt-l>", "NC_alt_search l");
  181.     assign_to_key ("<Alt-m>", "NC_alt_search m");
  182.     assign_to_key ("<Alt-n>", "NC_alt_search n");
  183.     assign_to_key ("<Alt-o>", "NC_alt_search o");
  184.     assign_to_key ("<Alt-p>", "NC_alt_search p");
  185.     assign_to_key ("<Alt-q>", "NC_alt_search q");
  186.     assign_to_key ("<Alt-r>", "NC_alt_search r");
  187.     assign_to_key ("<Alt-s>", "NC_alt_search s");
  188.     assign_to_key ("<Alt-t>", "NC_alt_search t");
  189.     assign_to_key ("<Alt-u>", "NC_alt_search u");
  190.     assign_to_key ("<Alt-v>", "NC_alt_search v");
  191.     assign_to_key ("<Alt-w>", "NC_alt_search w");
  192.     assign_to_key ("<Alt-x>", "NC_alt_search x");
  193.     assign_to_key ("<Alt-y>", "NC_alt_search y");
  194.     assign_to_key ("<Alt-z>", "NC_alt_search z");
  195.     assign_to_key ("<Alt-_>", "NC_alt_search _");
  196.     assign_to_key ("<Alt-0>", "NC_alt_search 0");
  197.     assign_to_key ("<Alt-1>", "NC_alt_search 1");
  198.     assign_to_key ("<Alt-2>", "NC_alt_search 2");
  199.     assign_to_key ("<Alt-3>", "NC_alt_search 3");
  200.     assign_to_key ("<Alt-4>", "NC_alt_search 4");
  201.     assign_to_key ("<Alt-5>", "NC_alt_search 5");
  202.     assign_to_key ("<Alt-6>", "NC_alt_search 6");
  203.     assign_to_key ("<Alt-7>", "NC_alt_search 7");
  204.     assign_to_key ("<Alt-8>", "NC_alt_search 8");
  205.     assign_to_key ("<Alt-9>", "NC_alt_search 9");
  206.  
  207.     drop_anchor (LINE);
  208.     message ("%s", current_dir);
  209.     refresh ();
  210.  
  211.     process ();
  212.  
  213.     keyboard_pop ();
  214.     delete_window ();
  215.     if (new_file != "")
  216.         {
  217.         if (new_file != "Load Multiple Files")
  218.             {
  219.             message ("Loading \"%s\" for editing...", new_file);
  220.             edit_file (new_file);
  221.             old_buffer = inq_buffer ();
  222.             }
  223.         else
  224.             {
  225.             top_of_buffer ();
  226.             while (search_fwd ("<\\c■"))
  227.                 {
  228.                 this_line = read ();
  229.                 down ();
  230.                 new_file = trim (substr (this_line, 3, 8));
  231.                 new_file += "." + trim (substr (this_line, 12, 3));
  232.                 message ("Loading \"%s\" for editing...", new_file);
  233.                 edit_file (new_file);
  234.                 old_buffer = inq_buffer ();
  235.                 set_buffer (dir_buffer);
  236.                 }
  237.             }
  238.         }
  239.     set_buffer (old_buffer);
  240.     delete_buffer (dir_buffer);
  241.     display_file_name ();
  242. }
  243.  
  244. no_beep (...)
  245. {
  246.     return;
  247. }
  248.  
  249. end_NC_alt (...)
  250. {
  251.     get_parm (0, alt_search);
  252.     exit ();
  253. }
  254.  
  255. NC_alt_search (...)
  256. {
  257.     extern    _do_beep;
  258.  
  259.     int    alt_line;
  260.  
  261.     string    alt_char;
  262.  
  263.     keyboard_push ();
  264.     assign_to_key ("<Enter>", "end_NC_alt <Enter>");
  265.     assign_to_key ("<Home>", "end_NC_alt <Home>");
  266.     assign_to_key ("<End>", "end_NC_alt <End>");
  267.     assign_to_key ("<Up>", "end_NC_alt <Up>");
  268.     assign_to_key ("<Down>", "end_NC_alt <Down>");
  269.     assign_to_key ("<PgUp>", "end_NC_alt <PgUp>");
  270.     assign_to_key ("<PgDn>", "end_NC_alt <PgDn>");
  271.     assign_to_key ("<Ins>", "end_NC_alt <Ins>");
  272.     assign_to_key ("<Ctrl-PgUp>", "end_NC_alt <Ctrl-PgUp>");
  273.     assign_to_key ("<F1>", "end_NC_alt <F1>");
  274.     assign_to_key ("<F2>", "end_NC_alt <F2>");
  275.     assign_to_key ("<F4>", "end_NC_alt <F4>");
  276.     assign_to_key ("<F7>", "end_NC_alt <F7>");
  277.     assign_to_key ("<F8>", "end_NC_alt <F8>");
  278.     assign_to_key ("<F9>", "end_NC_alt <F9>");
  279.     assign_to_key ("<F10>", "end_NC_alt <F10>");
  280.     assign_to_key ("<Esc>", "end_NC_alt <Esc>");
  281.     assign_to_key ("<Ctrl-\\>", "end_NC_alt <Ctrl-\\>");
  282.     assign_to_key ("<\\>", "end_NC_alt <\\>");
  283.     assign_to_key ("<Ctrl-R>", "end_NC_alt <Ctrl-R>");
  284.     assign_to_key ("<Keypad-minus>", "end_NC_alt <Keypad-minus>");
  285.     assign_to_key ("<Keypad-plus>", "end_NC_alt <Keypad-plus>");
  286.     assign_to_key ("<Alt-a>", "NC_alt a");
  287.     assign_to_key ("<Alt-b>", "NC_alt b");
  288.     assign_to_key ("<Alt-c>", "NC_alt c");
  289.     assign_to_key ("<Alt-d>", "NC_alt d");
  290.     assign_to_key ("<Alt-e>", "NC_alt e");
  291.     assign_to_key ("<Alt-f>", "NC_alt f");
  292.     assign_to_key ("<Alt-g>", "NC_alt g");
  293.     assign_to_key ("<Alt-h>", "NC_alt h");
  294.     assign_to_key ("<Alt-i>", "NC_alt i");
  295.     assign_to_key ("<Alt-j>", "NC_alt j");
  296.     assign_to_key ("<Alt-k>", "NC_alt k");
  297.     assign_to_key ("<Alt-l>", "NC_alt l");
  298.     assign_to_key ("<Alt-m>", "NC_alt m");
  299.     assign_to_key ("<Alt-n>", "NC_alt n");
  300.     assign_to_key ("<Alt-o>", "NC_alt o");
  301.     assign_to_key ("<Alt-p>", "NC_alt p");
  302.     assign_to_key ("<Alt-q>", "NC_alt q");
  303.     assign_to_key ("<Alt-r>", "NC_alt r");
  304.     assign_to_key ("<Alt-s>", "NC_alt s");
  305.     assign_to_key ("<Alt-t>", "NC_alt t");
  306.     assign_to_key ("<Alt-u>", "NC_alt u");
  307.     assign_to_key ("<Alt-v>", "NC_alt v");
  308.     assign_to_key ("<Alt-w>", "NC_alt w");
  309.     assign_to_key ("<Alt-x>", "NC_alt x");
  310.     assign_to_key ("<Alt-y>", "NC_alt y");
  311.     assign_to_key ("<Alt-z>", "NC_alt z");
  312.     assign_to_key ("<Alt-_>", "NC_alt _");
  313.     assign_to_key ("<Alt-0>", "NC_alt 0");
  314.     assign_to_key ("<Alt-1>", "NC_alt 1");
  315.     assign_to_key ("<Alt-2>", "NC_alt 2");
  316.     assign_to_key ("<Alt-3>", "NC_alt 3");
  317.     assign_to_key ("<Alt-4>", "NC_alt 4");
  318.     assign_to_key ("<Alt-5>", "NC_alt 5");
  319.     assign_to_key ("<Alt-6>", "NC_alt 6");
  320.     assign_to_key ("<Alt-7>", "NC_alt 7");
  321.     assign_to_key ("<Alt-8>", "NC_alt 8");
  322.     assign_to_key ("<Alt-9>", "NC_alt 9");
  323.  
  324.     unregister_macro (3, "_do_beep");
  325.     register_macro (3, "end_NC_alt");
  326.  
  327.     alt_done = FALSE;
  328.     inq_position (line, NULL);
  329.     top_of_buffer ();
  330.     get_parm (0, alt_char);
  331.     NC_alt (alt_char);
  332.  
  333.     process ();
  334.  
  335.     keyboard_pop ();
  336.     register_macro (3, "_do_beep");
  337.     unregister_macro (3, "end_NC_alt");
  338.  
  339.     push_back (key_to_int (alt_search));
  340.     alt_search = "\<■\|  ";
  341. }
  342.  
  343. NC_alt (...)
  344. {
  345.     string    alt_char;
  346.  
  347.     if (!alt_done)
  348.         {
  349.         get_parm (0, alt_char, "", 1);
  350.  
  351.         raise_anchor ();
  352.  
  353.         alt_search += alt_char;
  354.  
  355.         message ("Searching DIR for \"%s\".\*", substr (alt_search, 6));
  356.  
  357.         if (search_fwd (alt_search, TRUE, FALSE, FALSE))
  358.             inq_position (line, NULL);
  359.         else
  360.             alt_done = TRUE;
  361.  
  362.         message ("%s", current_dir);
  363.  
  364.         move_abs (line, 1);
  365.         drop_anchor (LINE);
  366.         refresh ();
  367.         }
  368.  
  369.     while (!inq_kbd_char ())
  370.         {
  371.         if (!(inq_kbd_flags () & ALT_KEY))
  372.             {
  373.             execute_macro ("end_NC_alt <Space>");
  374.             break;
  375.             }
  376.         }
  377.  
  378. }
  379.  
  380. change_drive (...)
  381. {
  382.     current_drive = "?";
  383.     new_file = "Change Drive";
  384.     while (current_drive != "" && (current_drive < "A" || current_drive > "Z"))
  385.         {
  386.         if (current_drive != "?")
  387.             beep ();
  388.         current_drive = "";
  389.         get_parm (NULL, current_drive, "Input New Drive Letter? ", 1);
  390.         if (current_drive == "?")
  391.             beep ();
  392.         current_drive = upper (current_drive);
  393.         }
  394.     if (current_drive >= "A" && current_drive <= "Z")
  395.         select_dir ();
  396.     else
  397.         {
  398.         message ("%s", current_dir);
  399.         current_drive = substr (current_dir, 1, 1);
  400.         new_file = "";
  401.         }
  402. }
  403.  
  404. make_dir (...)
  405. {
  406.     string    subdir;
  407.  
  408.     get_parm (NULL, subdir, "Name of SUB-DIR? ", 12);
  409.     if (subdir != "")
  410.         {
  411.         new_file = "Change Drive";
  412.         subdir = upper (subdir);
  413.         message ("Creating SUB-DIR \"%s\"...", subdir);
  414.         if (dos (("md " + subdir) + "\>\&tempmdir.err"))
  415.             error ("Unable to create %s SUB-DIR.", DOWN_DIR + subdir);
  416.         else
  417.             {
  418.             del ("tempmdir.err");
  419.             select_dir ();
  420.             }
  421.         }
  422.     else
  423.         message ("%s", current_dir);
  424. }
  425.  
  426. help_dir (...)
  427. {
  428.     extern    display_help;
  429.  
  430.     display_help ("dir");
  431.     message ("%s", current_dir);
  432.     keyboard_flush ();
  433. }
  434.  
  435. read_dir (...)
  436. {
  437.     new_file = "Change Drive";
  438.     select_dir ();
  439. }
  440.  
  441. up_1_dir (...)
  442. {
  443.     if (strlen (current_dir) > 3)
  444.         {
  445.         new_file = "Change Drive UP";
  446.         select_dir ();
  447.         }
  448.     else
  449.         beep ();
  450. }
  451.  
  452. root_dir (...)
  453. {
  454.     if (strlen (current_dir) > 3)
  455.         {
  456.         new_file = "Change Drive";
  457.         cd ("\\");
  458.         select_dir ();
  459.         }
  460.     else
  461.         beep ();
  462. }
  463.  
  464. delete_file (...)
  465. {
  466.     inq_position (line, NULL);
  467.     raise_anchor ();
  468.     top_of_buffer ();
  469.     if (search_fwd ("<\\c■"))
  470.         {
  471.         answer = "?";
  472.         while (upper (answer) != "Y" && upper (answer) != "N")
  473.             {
  474.             if (answer != "?")
  475.                 beep ();
  476.             answer = "";
  477.             get_parm (NULL, answer, "Delete ALL MARKED files \[YyNn\]? ", 1);
  478.             if (answer == "")
  479.                 answer = "N";
  480.             else
  481.                 if (answer == "?")
  482.                     beep ();
  483.             }
  484.         if (upper (answer) == "Y")
  485.             {
  486.             top_of_buffer ();
  487.             while (search_fwd ("<\\c■"))
  488.                 {
  489.                 this_line = read ();
  490.                 beginning_of_line ();
  491.                 down ();
  492.                 new_file = trim (substr (this_line, 3, 8));
  493.                 if (search_string ("DIR", this_line, NULL, 0))
  494.                     {
  495.                     if (substr (new_file, 1, 2) != "..")
  496.                         {
  497.                         if (substr (this_line, 12, 1) != " ")
  498.                             new_file += "." + trim (substr (this_line, 12, 3));
  499.                         error ("%s", this_line);
  500.                         message ("Deleting \"%s\" Directory...", new_file);
  501.                         dos ("rd " + (new_file + " \>&temp.err"));
  502.                         del ("temp.err");
  503.                         }
  504.                     }
  505.                 else
  506.                     {
  507.                     new_file += "." + trim (substr (this_line, 12, 3));
  508.                     message ("Deleting \"%s\" from DISK...", new_file);
  509.                     if (del (new_file) <= 0)
  510.                         {
  511.                         beep ();
  512.                         error ("Unable to delete \"%s\" - Hit ANY key ", new_file);
  513.                         while (!inq_kbd_char ())
  514.                             ;
  515.                         read_char ();
  516.                         }
  517.                     }
  518.                 }
  519.             }
  520.         else
  521.             {
  522.             move_abs (line, 1);
  523.             drop_anchor (LINE);
  524.             message ("%s", current_dir);
  525.             return;
  526.             }
  527.         }
  528.     else
  529.         {
  530.         move_abs (line, 1);
  531.         drop_anchor (LINE);
  532.         this_line = read ();
  533.         beginning_of_line ();
  534.         answer = "?";
  535.         while (upper (answer) != "Y" && upper (answer) != "N")
  536.             {
  537.             if (answer != "?")
  538.                 beep ();
  539.             answer = "";
  540.             get_parm (NULL, answer, "Delete HIGHLIGHTED FILE from DISK \[YyNn\]? ", 1);
  541.             if (answer == "")
  542.                 answer = "N";
  543.             else
  544.                 if (answer == "?")
  545.                     beep ();
  546.             }
  547.         if (upper (answer) == "Y")
  548.             {
  549.             new_file = trim (substr (this_line, 3, 8));
  550.             if (search_string ("DIR", this_line, NULL, 0))
  551.                 {
  552.                 if (substr (new_file, 1, 2) != "..")
  553.                     {
  554.                     if (substr (this_line, 12, 1) != " ")
  555.                         new_file += "." + trim (substr (this_line, 12, 3));
  556.                     message ("Deleting \"%s\" Directory...", new_file);
  557.                     dos ("rd " + (new_file + " \>&tempddir.err"));
  558.                     del ("tempddir.err");
  559.                     }
  560.                 }
  561.             else
  562.                 {
  563.                 new_file += "." + trim (substr (this_line, 12, 3));
  564.                 message ("Deleting \"%s\" from DISK...", new_file);
  565.                 if (del (new_file) <= 0)
  566.                     {
  567.                     beep ();
  568.                     error ("Unable to delete \"%s\" - Hit ANY key ", new_file);
  569.                     while (!inq_kbd_char ())
  570.                         ;
  571.                     read_char ();
  572.                     }
  573.                 }
  574.             }
  575.         else
  576.             {
  577.             message ("%s", current_dir);
  578.             return;
  579.             }
  580.         }
  581.     read_dir ();
  582. }
  583.  
  584. load_marked (...)
  585. {
  586.     inq_position (line, NULL);
  587.     this_line = read (16);
  588.     raise_anchor ();
  589.     top_of_buffer ();
  590.     if (search_fwd ("<\\c■"))
  591.         new_file = "Load Multiple Files";
  592.     else
  593.         {
  594.         if ("" == substr (this_line, 16, 1))
  595.             {
  596.             new_file = "";
  597.             beep ();
  598.             error ("DIRECTORIES may NOT be edited.  Hit ANY key...");
  599.             while (!inq_kbd_char ())
  600.                 ;
  601.             read_char ();
  602.             message ("%s", current_dir);
  603.             move_abs (line, 1);
  604.             drop_anchor (LINE);
  605.             return;
  606.             }
  607.         else
  608.             {
  609.             new_file = trim (substr (this_line, 3, 8));
  610.             new_file += "." + trim (substr (this_line, 12, 3));
  611.             }
  612.         }
  613.     exit ();
  614. }
  615.  
  616. top_of_dir (...)
  617. {
  618.     raise_anchor ();
  619.     top_of_buffer ();
  620.     drop_anchor (LINE);
  621. }
  622.  
  623. end_of_dir (...)
  624. {
  625.     raise_anchor ();
  626.     move_abs (end_line, 1);
  627.     beginning_of_line ();
  628.     to_bottom ();
  629.     drop_anchor (LINE);
  630. }
  631.  
  632. pgup_dir (...)
  633. {
  634.     extern    screen_down;
  635.  
  636.     int    count;
  637.  
  638.     raise_anchor ();
  639.     inq_position (line, NULL);
  640.     count = rows;
  641.     line -= count;
  642.     if (line > 1)
  643.         while (count)
  644.             {
  645.             screen_down ();
  646.             --count;
  647.             }
  648.     else
  649.         {
  650.         top_of_dir ();
  651.         return;
  652.         }
  653.     move_abs (line, 1);
  654.     drop_anchor (LINE);
  655. }
  656.  
  657. pgdown_dir (...)
  658. {
  659.     extern    screen_up;
  660.  
  661.     int    count;
  662.  
  663.     raise_anchor ();
  664.     inq_position (line, NULL);
  665.     count = rows;
  666.     line += count;
  667.     if (line <= end_line)
  668.         while (count)
  669.             {
  670.             screen_up ();
  671.             --count;
  672.             }
  673.     else
  674.         {
  675.         end_of_dir ();
  676.         return;
  677.         }
  678.     move_abs (line, 1);
  679.     drop_anchor (LINE);
  680. }
  681.  
  682. up_dir (...)
  683. {
  684.     raise_anchor ();
  685.     up ();
  686.     drop_anchor (LINE);
  687. }
  688.  
  689. down_dir (...)
  690. {
  691.     inq_position (line, NULL);
  692.     if (line != end_line)
  693.         {
  694.         raise_anchor ();
  695.         down ();
  696.         drop_anchor (LINE);
  697.         }
  698. }
  699.  
  700. mark_dir (...)
  701. {
  702.     this_line = read (16);
  703.  
  704.     if (substr (this_line, 16, 1) != "")
  705.         {
  706.         delete_char ();
  707.         if (search_string ("■", this_line, NULL, 0))
  708.             {
  709.             insert (" ");
  710.             }
  711.         else
  712.             {
  713.             insert ("■");
  714.             }
  715.         beginning_of_line ();
  716.         }
  717. }
  718.  
  719. convert_select (...)
  720. {
  721.     int    index_sel;
  722.  
  723.     string    temp_char,
  724.                 temp_sel;
  725.  
  726.     get_parm (0, select);
  727.     index_sel = 1;
  728.  
  729.     while (index_sel <= strlen (select))
  730.         {
  731.         temp_char = substr (select, index_sel, 1);
  732.         if (index ("\@\+\{\}\-\<\%\>\$", temp_char))
  733.             temp_sel += "\\";
  734.         temp_sel += temp_char;
  735.         ++index_sel;
  736.         }
  737.  
  738.     if (strlen (temp_sel))
  739.         temp_sel = ("■\|  " + temp_sel) + " @│";
  740.     else
  741.         temp_sel = "";
  742.  
  743.     put_parm (0, temp_sel);
  744. }
  745.  
  746. select_action (...)
  747. {
  748.     int    event_type,
  749.             line_no;
  750.  
  751.     string    button_text;
  752.  
  753.     get_parm (0, event_type);
  754.     get_parm (1, line_no);
  755.     get_parm (2, button_text);
  756.  
  757.     switch (event_type)
  758.         {
  759.         case DIALOG_ENTER_FIELD:
  760.             {
  761.             select = "\*.\*";
  762.             }
  763.         case DIALOG_EXIT_FIELD:
  764.             {
  765.             select = button_text;
  766.             put_parm (0, DIALOG_F10);
  767.             }
  768.         case DIALOG_ESCAPE:
  769.             {
  770.             select = "";
  771.             }
  772.         }
  773.     return TRUE;
  774. }
  775.  
  776. multiple_marks (...)
  777. {
  778.     int    line_no;
  779.  
  780.     raise_anchor ();
  781.     if (mark_typ == SELECT)
  782.         _process_dialog_box (cols + 11, 10, cols + 28, 8, "Select", "", "select", NULL, "select_action");
  783.     else
  784.         _process_dialog_box (cols + 11, 10, cols + 28, 8, "Unselect", "", "select", NULL, "select_action");
  785.     if (select != "")
  786.         {
  787.         convert_select (select);
  788.         get_parm (0, select);
  789.         message ("Marking specified files...");
  790.         inq_position (line, NULL);
  791.         line_no = end_line;
  792.  
  793.         while (line_no)
  794.             {
  795.             move_abs (line_no, 1);
  796.             this_line = read (16);
  797.             new_file = trim (substr (this_line, 1, 10));
  798.             new_file += "." + trim (substr (this_line, 12, 4));
  799.             if (search_string (select, new_file) && substr (this_line, 16, 1) != "")
  800.                 {
  801.                 delete_char ();
  802.                 switch (mark_typ)
  803.                     {
  804.                     case SELECT:
  805.                         insert ("■");
  806.                     case UNSELECT:
  807.                         insert (" ");
  808.                     }
  809.                 }
  810.             --line_no;
  811.             }
  812.         new_file = "";
  813.         move_abs (line, 1);
  814.         }
  815.     drop_anchor (LINE);
  816.     message ("%s", current_dir);
  817.     refresh ();
  818. }
  819.  
  820. select_marks (...)
  821. {
  822.     mark_typ = SELECT;
  823.     multiple_marks ();
  824. }
  825.  
  826. unselect_marks (...)
  827. {
  828.     mark_typ = UNSELECT;
  829.     multiple_marks ();
  830. }
  831.  
  832. select_dir (...)
  833. {
  834.     string    old_dir;
  835.  
  836.     updir = FALSE;
  837.     this_line = read (16);
  838.  
  839.     if ("" == substr (this_line, 16, 1) || substr (new_file, 1, 12) == "Change Drive")
  840.         {
  841.         if (search_string ("..", this_line, NULL, 0) || substr (new_file, 1, 12) == "Change Drive")
  842.             {
  843.             if (new_file == "Change Drive")
  844.                 {
  845.                 cd (current_drive + ":");
  846.                 }
  847.             else
  848.                 {
  849.                 cd (UP_DIR);
  850.                 updir = TRUE;
  851.                 }
  852.             new_file = "";
  853.             }
  854.         else
  855.             {
  856.             new_file = trim (substr (this_line, 3, 8));
  857.             if (substr (this_line, 12, 1) != " ")
  858.                 new_file += "." + trim (substr (this_line, 12, 3));
  859.             cd (DOWN_DIR + new_file);
  860.             new_file = "";
  861.             }
  862.  
  863.         raise_anchor ();
  864.         top_of_buffer ();
  865.         drop_anchor (LINE);
  866.         move_abs (end_line, 1);
  867.         delete_block ();
  868.         top_of_buffer ();
  869.         refresh ();
  870.         message ("Reading disk directory...");
  871.         dos (bdir);
  872.         old_dir = current_dir;
  873.         getwd (NULL, current_dir);
  874.         current_dir = upper (current_dir);
  875.         current_drive = substr (current_dir, 1, 1);
  876.         read_file (bdirfile);
  877.         up ();
  878.         inq_position (end_line, NULL);
  879.         top_of_buffer ();
  880.  
  881.         if (updir)
  882.             {
  883.             updir = strlen (current_dir);
  884.             if (updir < strlen (old_dir))
  885.                 {
  886.                 int    dot;
  887.  
  888.                 if (updir > 3)
  889.                     ++updir;
  890.                 ++updir;
  891.                 select = upper (substr (old_dir, updir));
  892.                 dot = index (select, ".");
  893.                 if (dot)
  894.                     select = (substr (select, 1, dot - 1) + " \+") + substr (select, dot + 1);
  895.                 search_fwd (select);
  896.                 beginning_of_line ();
  897.                 }
  898.             updir = FALSE;
  899.             }
  900.  
  901.         drop_anchor (LINE);
  902.         message ("%s", current_dir);
  903.         refresh ();
  904.         }
  905.     else
  906.         {
  907.         new_file = trim (substr (this_line, 3, 8));
  908.         new_file += "." + trim (substr (this_line, 12, 3));
  909.         exit ();
  910.         }
  911. }
  912.  
  913. set_mode (...)
  914. {
  915.     old_opt = bdiropt;
  916.     push_back (key_to_int (bdiropt));
  917.     _process_dialog_box (cols - 3, 10, cols + 44, 8, "Sort DIR by", "", "setmode", NULL, "mode_action");
  918.     if (old_opt != bdiropt)
  919.         {
  920.         bdiropt = old_opt;
  921.         bdir = bdirpgm + ((" \-" + bdiropt) + (" \>&" + bdirfile));
  922.         read_dir ();
  923.         }
  924.     else
  925.         message ("%s", current_dir);
  926. }
  927.  
  928. mode_action (...)
  929. {
  930.     int    event_type,
  931.             line_no;
  932.  
  933.     string    button_text;
  934.  
  935.     get_parm (0, event_type);
  936.     get_parm (1, line_no);
  937.     get_parm (2, button_text);
  938.  
  939.     switch (event_type)
  940.         {
  941.         case DIALOG_ENTER_LIST:
  942.             {
  943.             old_opt = substr (button_text, 1, 1);
  944.             }
  945.         case DIALOG_ALTER_LIST:
  946.             {
  947.             old_opt = substr (button_text, 1, 1);
  948.             put_parm (0, DIALOG_F10);
  949.             }
  950.         case DIALOG_ESCAPE:
  951.             {
  952.             old_opt = bdiropt;
  953.             }
  954.         }
  955.     return TRUE;
  956. }
  957.